package cn.bdqn.smbms.service;

import cn.bdqn.smbms.dao.ProviderDao;
import cn.bdqn.smbms.entity.Provider;
import cn.bdqn.smbms.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("providerService")
public class ProviderServiceImpl implements  ProviderService {

    @Autowired
    private ProviderDao providerDao;

    @Override
    public List<Provider> findAll() {
        return providerDao.findAll();
    }

    @Override
    public PageBean<Provider> findByPage(String queryProCode,String queryProName,Integer pageNo, Integer pageSize) {
        PageBean<Provider> pageBean = new PageBean<>();
        pageBean.setPageSize(pageSize);
        pageBean.setTotalCount(providerDao.totalCount(queryProCode,queryProName));
        pageBean.setPageNo(pageNo);
        int from = (pageBean.getPageNo()-1)*pageSize;
        List<Provider> pageList = providerDao.findByPage(queryProCode,queryProName,from,pageSize);
        pageBean.setPageList(pageList);
        return pageBean;
    }

    @Override
    public int addProvider(Provider provider) {
        return providerDao.addProvider(provider);
    }

    @Override
    public Provider findById(Integer id) {
        return providerDao.findById(id);
    }

    @Override
    public int updateProvider(Provider provider) {
        return providerDao.updateProvider(provider);
    }

    @Override
    public int delProvider(Integer id) {
        return providerDao.delProvider(id);
    }

    @Override
    public boolean checkProCode(String proCode) {
        Provider provider = providerDao.findByProCode(proCode);
        if(provider!=null){
            return true;//找到了
        }
        return false;
    }

}
